package org.example.test.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.example.test.entity.Recruit;
import org.example.test.service.RecruitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/recruit")
public class RecruitController {
@Autowired
    RecruitService recruitService;
    @RequestMapping("/recruits")
    public Map<String, Object>recruits(Integer pageNum, Integer pageSize,String recruitName){
        //既存放数据，又存放总条数
        Map<String, Object> map = new HashMap<String, Object>();
        Page<Object> startPage = PageHelper.startPage(pageNum, pageSize);
        map.put("recruitList", recruitService.findAll(recruitName));//向容器中放获取到的数据
        map.put("total", startPage.getTotal());//向容器中放数据总条数
        return map;
    }
    @RequestMapping("/delete")
        public int delete(Integer recruitId){
        return recruitService.delete(recruitId);
    }
    @RequestMapping("/add")
    public int add(@RequestBody Recruit recruit){
        return recruitService.add(recruit);
    }
    @RequestMapping("/update")
    public int update(@RequestBody Recruit recruit){
        return recruitService.update(recruit);
    }
}
